package genetic.treenodes;

import genetic.Arity;
import genetic.DataSet;
import genetic.GPTreeNode;

public class IfEqualThenElse extends GPTreeNode implements Cloneable {
	
	@Override
	public double getValue(DataSet ds) {

		if (Math.abs(children.get(0).getValue(ds) - children.get(1).getValue(ds)) < 0.0001)
			return children.get(2).getValue(ds);
		else
			return children.get(3).getValue(ds);
	}

	@Override
	public Arity getArity() {
		return Arity.four;
	}
	
	public IfEqualThenElse clone() {
		return (IfEqualThenElse)super.clone();
	}

	/* (non-Javadoc)
	 * @see javax.swing.tree.TreeNode#getAllowsChildren()
	 */
	@Override
	public boolean getAllowsChildren() {
		return true;
	}

	/* (non-Javadoc)
	 * @see javax.swing.tree.TreeNode#isLeaf()
	 */
	@Override
	public boolean isLeaf() {
		return false;
	}
	
}
